package view;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import model.CardStack;
import model.GameModel;

class PopClickListener extends MouseAdapter 
{
	TableComponent table;
	HandComponent hand;
	
	public PopClickListener(TableComponent table, HandComponent hand)
	{
		this.table = table;
		this.hand = hand;
	}
	
	
    public void mousePressed(MouseEvent e){
        if (e.isPopupTrigger() && e.getButton() == 3)
            doPop(e);
    }

    public void mouseReleased(MouseEvent e){
        if (e.isPopupTrigger() && e.getButton() == 3)
            doPop(e);
    }

    private void doPop(MouseEvent e){

 //   	System.out.println("right click!" + e.getButton());
    	
        int mx = e.getXOnScreen() - table.getLocationOnScreen().x;
        int my = e.getYOnScreen() - table.getLocationOnScreen().y;
        
        CardStack stack = table.getStackAt(mx, my);
 
    	//pass in table here..
        PopUpMenu menu = new PopUpMenu(table, hand);

        if (stack != null && stack.isHighlighted())
        {
        	menu.setStack(stack);
            
        }
        	
        else if (stack != null && stack.isTopHighlighted())
        {
        	menu.setStack(stack);
        	
        }
        
        menu.show(e.getComponent(), e.getX(), e.getY());

        
        
    }
}